home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7097 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: cafu.fl.net.au!usenet
  2. From: als@fl.net.au (Andrew Snow)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How to tell if a file exists in C
  5. Date: Sun, 18 Feb 1996 10:09:44 GMT
  6. Organization: First Link Internet Services
  7. Message-ID: <4g8132$mg9@cafu.fl.net.au>
  8. References: <4eqkj6$ipo@charm.magnus.acs.ohio-state.edu> <4eqn9q$dr1@sparcserver.lrz-muenchen.de> <3121db3e.43150046@nntp.ix.netcom.com> <4ftpnk$i74@cafu.fl.net.au> <824493561snz@genesis.demon.co.uk>
  9. NNTP-Posting-Host: snowville.fl.net.au
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Lawrence Kirby <fred@genesis.demon.co.uk> wrote:
  13.  
  14. >In article <4ftpnk$i74@cafu.fl.net.au> als@fl.net.au "Andrew Snow" writes:
  15.  
  16. >>How about plain old:
  17. >>
  18. >>        if(0==access("filename", F_OK))
  19. >>                {
  20. >>                do stuff with file();
  21. >>                }
  22. >>        else
  23. >>                {
  24. >>                error();
  25. >>                }
  26. >>
  27. >>This works O.K. under Linux and FreeBSD, and most DOS compilers.
  28.  
  29. >access() is a specialised function under Unix/POSIX to test permissions
  30. >against the real user/group ID's. If you don't want to do that specifically
  31. >you should never use access() (and why on other systems you should avoid it
  32. >where portability is concerned). stat() is the way to go in that case.
  33.  
  34. Specialised?  well its a part of every single DOS compiler I've ever
  35. seen.  
  36.  
  37. >However neither of these are as portable as fopen() since that is defined by
  38. >the C language.
  39.  
  40. True, however I was only offering access() as a viable alternative.
  41.  
  42. >>If you want to see if the file is readable as well as exists,
  43.  
  44. >Can a file be readable yet not exist?
  45.  
  46. No, but did you really want me to spell it out?  You ought to have
  47. been able to figure it out. Sorry if you couldn't.
  48.  
  49. ----
  50. Andrew Snow
  51. als@fl.net.au
  52. http://www-als.fl.net.au
  53.  
  54.